<@pp.dropOutputFile />
<#import "../lib/lib.ftl" as lib/>
<#list dalgen.tables as table>
<@pp.changeOutputFile name = "/${dalgen.tablesPath}/${table.sqlName}.xml" />
<!DOCTYPE table SYSTEM "../config/table-config-1.0.dtd">
<table sqlname="${table.sqlName}" physicalName="${table.physicalName}"<#if table.remark??> remark="${table.remark!}"</#if>>
    <!--  特殊字符说明  &lt;&gt;   <> -->

    <operation name="insert" paramtype="object" remark="插入表:${table.sqlName}">
        <#if dalgen.dbType=="MySQL">
        <selectKey resultType="java.lang.Long" keyProperty="id" order="AFTER">
            SELECT
            LAST_INSERT_ID()
        </selectKey>
        </#if>
        INSERT INTO ${table.sqlName}(
        <#list table.columnList as column>
            <#if column_index gt 0>,</#if>${column.sqlName}
        </#list>
        )VALUES(
        <#list table.columnList as column>
            <#if column_index gt 0>,</#if> ${lib.insertVal(column)}
        </#list> 
        )
    </operation>
    
    <operation name="deleteById" paramtype="primitive" remark="根据主键删除数据:${table.sqlName}">
        delete FROM ${table.sqlName}   WHERE ID =  ${"#"}{id,jdbcType=BIGINT}
    </operation>
    
    <operation name="deleteBusinessById" paramtype="primitive" remark="根据主键业务删除数据:${table.sqlName}">
        UPDATE FROM ${table.sqlName} SET DELETE_FLAG = 1  WHERE ID =  ${"#"}{id,jdbcType=BIGINT}
    </operation>
	
	<!-- 要更新成null值，请在业务层做 针对每个对象 设置某个默认值 则是将该字段设置为空 -->
    <operation name="updateById" paramtype="primitive" remark="更新表:${table.sqlName}">
        UPDATE ${table.sqlName}
        <trim prefix="set" prefixOverrides=",">
	        <#list table.columnList as column>
	            <#if lib.updateIncludeColumn(column,table.primaryKeys.columnList)>
	            	<if test="${column.sqlName} != null">
	            		,${column.sqlName} = ${lib.updateVal(column)}
	            	</if>
	            </#if>
	        </#list>
	        ,UPDATED_DATE = now()
	    </trim>
        WHERE ID = ${"#"}{id,jdbcType=BIGINT} AND DELETE_FALG = 0 
    </operation>

    <operation name="queryById" multiplicity="one" paramtype="primitive" remark="根据主键获取数据:${table.sqlName}">
        SELECT *
        FROM ${table.sqlName}
        WHERE ID = ${"#"}{id,jdbcType=BIGINT} AND DELETE_FALG = 0 
    </operation>
    
    <operation name="query${table.javaName}" multiplicity="many" remark="根据主键获取数据:${table.sqlName}">
        SELECT *
        FROM ${table.sqlName}
        <trim prefix="where" prefixOverrides="and ">
	        <#list table.columnList as column>
	        	<if test="${column.sqlName} != null ">
	            	AND  ${column.sqlName} = ${"#"}{${column.javaName},jdbcType=${column.sqlType}}
	            </if>
	        </#list>
        	AND DELETE_FALG = 0 
        </trim>
        order by update_date desc 
    </operation>
    
    <operation name="query${table.javaName}ByDeleted" multiplicity="many" paramtype="object" remark="根据主键获取数据:${table.sqlName}">
        SELECT *
        FROM ${table.sqlName}
        <trim prefix="where" prefixOverrides="and ">
	        <#list table.columnList as column>
	        	<if test="${column.sqlName} != null ">
	            	AND  ${column.sqlName} = ${"#"}{${column.javaName},jdbcType=${column.sqlType}}
	            </if>
	        </#list>
        	AND DELETE_FALG = 1
        </trim>
        order by update_date desc 
    </operation>

	<operation name="query${table.javaName}page" multiplicity="paging" paging="Query${table.javaName}s" remark="根据主键获取数据:${table.sqlName}">
        SELECT *
        FROM ${table.sqlName}
        <trim prefix="where" prefixOverrides="and ">
	        <#list table.columnList as column>
	        	<if test="${column.sqlName} != null">
	            AND  ${column.sqlName} = ${"#"}{${column.javaName},jdbcType=${column.sqlType}}
	            </if>
	        </#list>
        	AND DELETE_FALG = 0 
        </trim>
        order by update_date desc 
    </operation>
</table>
</#list>